// issues.js
let util = require('../../utils/util.js')
let app = getApp()
let that
let userInfo
Page({
  data: {
    title: '',
    content: '',
    showTopTips: false,
    isdisabled: false,
    TopTips: '',
    info: ''
  },
  onLoad: function () {
    that = this
    userInfo = wx.getStorageSync('userInfo') || false
    if (userInfo) {
      app.reg(userInfo)
      that.setData({//初始化数据
        isLoading: false,
        isdisabled: false
      })
      //获取设备和用户信息
      wx.getSystemInfo({
        success: function (res) {
          let info = '---\r\n**用户信息**\r\n'
          info += '用户名：' + userInfo.nickName
          info += '\r\n手机型号：' + res.model
          info += '（' + res.platform + ' - ' + res.windowWidth + 'x' + res.windowHeight + '）'
          info += '\r\n微信版本号：' + res.version
          that.setData({
            info: info
          })
        }
      })
    }

    wx.setNavigationBarTitle({
      title: "倩狐互动-反馈",
    })
  },
  //表单验证
  showTopTips: function () {
    that.setData({
      showTopTips: true
    })
    setTimeout(function () {
      that.setData({
        showTopTips: false
      })
    }, 3000)
  },
  //提交表单
  submitForm: function (e) {
    let title = e.detail.value.title
    let content = e.detail.value.content
    //先进行表单非空验证
    if (title == "") {
      that.setData({
        showTopTips: true,
        TopTips: '请输入反馈标题'
      })
    } else if (content == "") {
      that.setData({
        showTopTips: true,
        TopTips: '请输入反馈内容'
      })
    } else {
      that.setData({
        isLoading: true,
        isdisabled: true
      })
      wx.showModal({
        title: '提示',
        content: '是否确认提交反馈',
        success: function (res) {
          if (res.confirm) {
            app.ajax({
              url: "/wechat/Issues/add", data: { openId: userInfo.openId, title: title, content: content, info: that.data.info },
              success: function (json) {
                that.setData({
                  showTopTips: false,
                  isLoading: false,
                  isdisabled: false,
                  title: '',
                  content: ''
                })
              }
            })
          }
        }
      })
    }
  }

})